﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using V5_Common;
using V5_Model;
using V5_BLL;

namespace V5_EShop._Template.Default.Member
{
    public partial class Personal : BasicPage
    {
        public string s1 = "", s2 = "", s3 = "";
        protected override void OnInit(EventArgs e)
        {
            this.btnSave.Click += new EventHandler(btnSave_Click);
            base.OnInit(e);
        }

        void btnSave_Click(object sender, EventArgs e)
        {
            int id = Input.SetInt(user.ID);
            if (id > 0)
            {
                ModelUser model = new BLLUser().GetModel(id);
                model.TrueName = txtUserName.Text;
                model.UserSex = Input.SetInt(ddlUserSex.SelectedValue);
                model.BirthDay = txtUserBirthDay.Text;
                model.IdentityCard = txtUserIdentityCard.Text;
                model.UserEmail = txtUserEmail.Text;
                model.Telephone = txtUserTelephone.Text;
                model.Phone = txtUserPhone.Text;
                model.PostCode = Input.SetInt(txtUserPostCode.Text);
                model.Address = this.Tprovince.Value;
                model.Address2 = this.TCity.Value;
                model.Address3 = this.TCounty.Value;
                model.Readme = txtUserReadme.Text;
                new BLLUser().Update(model);
                Pr.RegClientAlertAndRedirect(this, "恭喜您!修改成功!", HTTPS.ComeUrl);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.check_member_login())
            {
                Response.Redirect("/login.aspx?returnurl=" + HTTPS.GetCurrentUrl());
            }
            if (!this.IsPostBack)
            {
                txtUserName.Text = user.TrueName;
                ddlUserSex.SelectedIndex = ddlUserSex.Items.IndexOf(ddlUserSex.Items.FindByValue(user.UserSex.ToString()));
                txtUserBirthDay.Text = user.BirthDay;
                txtUserIdentityCard.Text = user.IdentityCard;
                txtUserEmail.Text = user.UserEmail;
                txtUserTelephone.Text = user.Telephone;
                txtUserPhone.Text = user.Phone;
                //所属区域
                txtUserPostCode.Text = user.PostCode.ToString();
                txtUserReadme.Text = user.Readme;//说明
                //
                s1 = user.Address;
                s2 = user.Address2;
                s3 = user.Address3;
            }
        }
    }
}
